• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

AltME groups: search

Help · search scripts · search articles · search mailing list

results summary

worldhits
r4wp0
r3wp13
total:13

results window for this page: [start: 1 end: 13]

world-name: r3wp

Group: All ... except covered in other channels [web-public]
btiffin:
9-Jan-2009
Gabriele; no sorry; I guess I obfuscated my point too much with the 
money! example.  I don't want REBOL to figure out all the possible 
human combinations of money.  I want REBOL to load a value that we 
humans commonly use as a format of money, without a syntax error. 
  The make phase would create a foreign data value and keep going. 
  Let the gurus that write general applications worry about the math 
operations on junk and account for it.  But let a professor load 
his book and use the uber powerful series operations of REBOL for 
ad hoc analysis.   No AI involved here, just a feature of the language 
that "if a piece of source does not match one of the lexically strict 
57 datatypes, it floats in a REBOL block as foreign".    And foreign 
is similar but not quite exactly the same as quoting the text as 
string!, without need of quoting the text.   I see great power in 
this feature.


Excuse the poor example;   I misdirected my intention when I mentioned 
that arg1 had a good hint, my mistake (but I would if I had brains, 
include this hint as a subfield of foreign! data, just because, why 
not, the current lexical parser already made a guess).  Our good 
Mr Hawley has a plan for a LOAD refinement /else with a type spec 
that looks very promising, but then it leads to being able to distinguish 
actual quoted input from coerced input, so I still lean toward foreign.


My plan (and I place burden of foreign! management for CODE blocks 
to the gurus) would let normal people load any data and run with 
it.  Even it they only use 4 or 5 REBOL functions at the console, 
the potential userbase becomes orders of magnitude greater than what 
we have today.   That it turn opens up a few that will write concise 
clear time lasting code that could analyze books or the sum of human 
knowledge using our favourite thinking environment.  No?
Group: Rebol School ... Rebol School [web-public]
Gregg:
3-Jan-2009
fold: func [ ; i.e. Haskell foldl (fold left). Same as 'reduce in 
Python?
        series [series!]
        fn     [any-function!]
        /with  value "starting value; used as accumulator"
    ][
        if not with [value: pick series 1  series: next series]
        foreach item series [value: fn value item]
    ]
    sum: func [block [any-block!]] [fold block :add]

    product: func [block [any-block!]] [fold/with block :multiply 1]
    sum-of-squares: func [block [any-block!]] [
        fold block func [x y] [x * x + y] 0
    ]
Group: !REBOL3-OLD1 ... [web-public]
Volker:
23-Dec-2006
Maxims approach is used in vid, where the wall is not the end of 
block but something "wrong". IE it could be standart to terminate 
such things with a dot.
  a: sum 1 2 3 4 .  print a

all needed would be a way to parse the callers code, i wish that 
for years. Other question is if is really is needed. blocks work, 
and the reduce can be done inside the function.
Gregg:
24-Jul-2007
Question: How useful would you find the following, and what other 
aggregate funcs would you find most useful? 

fold: func [
	block [any-block!] "Block of values"
	accum "Accumulator value" 
	f [any-function!] "Function to apply"
][
    foreach val block [accum: f :accum :val]
]
sum: func [block [any-block!]] [fold block 0 :add]
product: func [block [any-block!]] [fold block 1 :multiply]
average: func [block [any-block!]][
    if empty? block [return none]
    divide  sum block  length? block
]
Geomol:
24-Jul-2007
If you choose new functions like SUM, someone might argue, that JOIN 
with a block as second argument should be another function taking 
only one argument:
JOINALL ["a" "b" 2]
or REJOIN (that we have) if the block should be reduced.
Gregg:
24-Jul-2007
SUM is a standard term, and a common aggregate func. It could be 
a shortcut for "add number block". Generally, I like the idea of 
"overloading" funcs to make them smarter, e.g. a dialected version 
of EXTRACT is high on my list, but it's a fine line, and each choice 
has to be made carefully.
Maxim:
29-Oct-2009
we reallly need to get 'SUM into R3... its just  soooooo slow to 
sum values in a block using rebol iteration.

as in
>> SUM [ 1 2 3 4]
== 10
Gregg:
31-Dec-2009
I'm all for it. I've suggested them in the past, but didn't get much 
traction. Here's a non-recursive starting point.

    ; Should our seed value be 0.0 to coerce to decimal? If they
    ; include a decimal value before any overflow, it will be OK.
    ; Changed to match the first type in the block.
    sum: func [block [any-block!] /local result] [
        result: any [
            attempt [make pick block 1 0]
            attempt [0 * pick block 1]
            0
        ]
        foreach value reduce block [result: result + value]
        result
    ]
BrianH:
31-Dec-2009
sum: func [block [block! vector!] /local result] [
    result: 0
    foreach value reduce block [result: result + :value]
    result
]
Steeve:
31-Dec-2009
uggly one-liner version.

sum: func[block [block!]][

 foreach [v1: v2] next head reduce/into block copy [0 0][v1/1: :v2 
 + v1/0]
]
-_-;
Group: !Liquid ... any questions about liquid dataflow core. [web-public]
Josh:
26-Feb-2009
I finally started playing around with liquid.r   Having a little 
trouble conceptually with converting code that contains objects into 
the data-flow model.  For example, I was fiddling around with a D&D 
character generator.  I have an ABILITY! object class that I'm trying 
to convert to the model now.  SUM is just a function that adds up 
all the values in a block


ability:  [[1 -5] [2 -4] [3 -4] [4 -3] [5 -3] [6 -2] [7 -2] [8 -1] 
[9 -1] [10 0] [11 0] [12 1] [13 1] [14 2] [15 2] [16 3] [17 3] [18 
4]]
ability!: make object! [
	base: 0
	modifiers: [0 0]
	total: does [base + sum modifiers]
	ability-mod: does [ability/(total)/2]
]


It may be a lot to ask, but would it be possible for someone to convert 
this to liquid, so I can actually see how one creates this kind of 
hierarchy in data flowprogramming.
Group: !REBOL3 ... [web-public]
BrianH:
7-Oct-2010
Here's a low-level function to parse and process script headers, 
which shows how many features are built into the base script model 
in R3:

load-script: funct [
	"Decode a script into [header-obj script-ref body-ref]"

 source [binary! string!] "Source code (string will be UTF-8 encoded)"
	/header "Return the header object only, no script processing"

 ;/check "Calculate checksum and assign it to the header checksum 
 field"
	/original "Use original source for Content header if possible"
] compose [
	data: either string? source [to-binary source] [
		unless find [0 8] tmp: utf? source [ ; Not UTF-8
			cause-error 'script 'no-decode ajoin ["UTF-" abs tmp]
		]
		source
	]

 ; Checksum all the data, even that before the header or outside the 
 block
	;sum: if check [checksum/secure data]  ; saved for later
	
	if tmp: script? data [data: tmp] ; Find the start of the script
	
	; Check for a REBOL header
	set/any [hdr: rst:] transcode/only data
	unless case [
		:hdr = 'rebol [ ; Possible REBOL header
			set/any [hdr rst] transcode/next/error rst
			block? :hdr ; If true, hdr is header spec
		]
		:hdr = [rebol] [ ; Possible script-in-a-block
			set/any [hdr rst] transcode/next/error rst
			if block? :hdr [ ; Is script-in-a-block
				unless header [ ; Don't decode the rest if /header
					data: first transcode/next data
					rst: skip data 2
				]
				true
			] ; If true, hdr is header spec
		]
	] [ ; No REBOL header, use default
		hdr: [] rst: data
	]
	; hdr is the header spec block, rst the position afterwards

 ;assert/type [hdr block! data [binary! block!] rst [binary! block!]]
	;assert [same? head data head rst]
	
	; Make the header object, or fail if we can't

 unless hdr: attempt [construct/with :hdr system/standard/header] 
 [
		cause-error 'syntax 'no-header data
	]
	; hdr is a correct header object! here, or you don't get here

 ;if check [append hdr 'checksum  hdr/checksum: sum]  ; calculated 
 earlier

 ;assert [sum =? select hdr 'checksum]  ; Should hdr/checksum be reserved?
	

 if header [return hdr] ; If /header, no further processing necessary

 ; Note: Some fields may not be final because post-processing is not 
 done.
	
	; Skip any whitespace after the header

 ws: (charset [1 - 32]) ; For whitespace skipping (DEL not included)
	if binary? rst [parse rst [any ws rst:]] ; Skip any whitespace
	
	; Check for compressed data and decompress if necessary
	case [
		; Magic autodetection of compressed binary
		tmp: attempt [decompress rst] [
			data: rst: tmp  ; Use decompressed data (no header source)
			append hdr 'compressed  hdr/compressed: true ; Just in case
		]
		; Else not directly compressed (without encoding)
		(select hdr 'compressed) != true [] ; Not declared, do nothing
		; Else it's declared to be compressed, thus should be
		binary? rst [ ; Regular script, check for encoded binary
			set/any [tmp rst] transcode/next/error rst
			either tmp: attempt [decompress :tmp] [
				data: rst: tmp  ; Use the decoded binary (no header source)
				hdr/compressed: 'script  ; So it saves the same way
				; Anything after the first binary! is ignored
			] [cause-error 'script 'bad-press -3] ; Else failure
		]
		; Else it's a block, check for script-encoded compressed binary
		tmp: attempt [decompress first rst] [

   data: rst: tmp  hdr/compressed: 'script  ; It's binary again now
		]
		; Else declared compressed but not compressed, so fail
		'else [cause-error 'script 'bad-press -3]
	]
	
	; Save the script content in the header if specified
	if :hdr/content = true [
		hdr/content: either original [source] [copy source]
	]
	

 ;assert/type [hdr object! data [binary! block!] rst [binary! block!]]
	;assert [same? head data head rst]

 reduce [hdr data rst]  ; Header object, start of source, start of 
 body
]


Note all the commented assert statements: they are for testing (when 
uncommented) and documentation. Also, I later removed the checksum 
calculation from this code because it was the wrong place to put 
it, at least as far as modules are concerned. However, Carl didn't 
know this because he was working on it while I was offline for a 
few days.
Maxim:
19-Apr-2011
yeah, we should have block versions of the various math ops as standard 
in the language.  
 similar to any/all for conditionals.

something like:
sum [ 1 2 3 4 5 6 ]
min/max-of [ 1 2 3 4 5 6 ]
etc.